import http from "@/http";

export const userListApi = (
  params: IUserListParams
): RES<IUserListModel<IUserModel>> => http.get("/admin/list", { params });

export const switchUserStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserApi = (params: IUserModel): RES<IUserModel> =>
  http.post("/admin/register", params);

export const getUserById = (id: number): RES<IUserModel> =>
  http.get(`/admin/${id}`);

export const updateUser = (params: IUserModel): RES<number> =>
  http.post(`/admin/update/${params.id}`, params);

export const getRoleListApi = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

export const getRolesByUserIdApi = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

export const updateUserRolesApi = (id: number, ids: number[]): RES<number> =>
  http.post(`/admin/role/update?adminId=${id}&roleIds=${ids.join(",")}`);
export const getUserRoleAPI = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);
export const updateRoleAPI = (id: number, ids: number[]): RES<number> =>
  http.post(`/admin/role/update?adminId=${id}&roleIds=${ids}`);

export const RoleListAPI = (
  params: IUserListParams
): RES<ITableResult<IRoleModel>> => http.get(`/role/list`, { params });

export const switchRoleStatusAPI = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);

export const editRoleAPI = (params: IRoleModel): RES<number> =>
  http.post(`/role/update/${params.id}`, params);

export const addRoleAPI = (params: IRoleModel): RES<IRoleModel> =>
  http.post("/role/create", params);

export const getRourceListByRoleIdApi = (
  roleId: number
): RES<IResourceModel[]> => http.get(`/role/listResource/${roleId}`);

export const resourceListAllApi = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");

export const resourceCategoryAllApi = (): RES<IResourceCategoryModel[]> =>
  http.get(`/resourceCategory/listAll`);

export const allocResourceApi = (paramas: IAllocResourcePramas) =>
  http.post(
    `/role/allocResource?roleId=${
      paramas.roleId
    }&resourceIds=${paramas.resourceIds.join(",")}`
  );

// 获取分配资源的所有资源
export const treeListApi = (): RES<ItreeMenu[]> => http.get("/menu/treeList");

// 根据ID获取菜单详情
export const getUserMenuByIdApi = (roleId: number): RES<IMenuModel[]> =>
  http.get(`/role/listMenu/${roleId}`);

// 分配菜单
export const allocMenuApi = (params: IAllocMenuParams): RES<any> =>
  http.post(
    `/role/allocMenu?roleId=${params.roleId}&menuIds=${params.menuIds.join(
      ","
    )}`
  );

// 资源列表
export const resourceListApi = (
  params: IResourceList
): RES<IUserListModel<IResourceModel>> =>
  http.get("/resource/list", { params });

// 菜单列表
export const menuListbyParentIdApi = (
  params: IMenuListParams
): RES<IUserListModel<IMenuModel>> =>
  http.get(
    `/menu/list/${params.parentId}?pageNum=${params.pageNum}&pageSize=${params.pageSize}`
  );

// 菜单切换显示隐藏
export const menuUpdateHiddenApi = (id: number, hidden: number): RES<number> =>
  http.post(`/menu/updateHidden/${id}?hidden=${hidden}`);


// 添加菜单
export const addMenuApi = (params: IMenuAddParams): RES<number> =>
  http.post("/menu/create", params);

// id获取菜单详情
export const getMenuByIdApi = (id: number): RES<IMenuAddParams> =>
  http.get(`/menu/${id}`);

// 修改菜单
export const updateMenuApi = (params: IMenuAddParams) =>
  http.post(`/menu/update/${params.id}`, params);

